package za.org.jcicada.comms;

import java.io.IOException;

import za.org.jcicada.comms.messages.CommsMessage;

/**
 * Interface defined for all serialisation strategies to implement.
 * @author rcrida
 */
public interface IMessageSerializerStrategy {

    /**
     * Serialize a CommsMessage to an array of bytes.
     *
     * @param msg  Message to serialize.
     * @return  Byte array representing the message.
     * @throws IOException  if serialization fails.
     */
    byte[] toBytes(CommsMessage msg) throws IOException;
    
    /**
     * Deserialize a CommsMessage from an array of bytes.
     *
     * @param bytes  Byte array to deserialize.
     * @return  The message.
     * @throws IOException  if deserialization fails.
     */
    CommsMessage fromBytes(byte[] bytes) throws IOException;
}
